package com.songqintuan.common.logging;

import java.sql.Timestamp;


import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import com.songqintuan.common.config.ConfigManager;

public class Log {
	private static Log ourInstance;
	
	private static Logger logger;
	
	static {
		PropertyConfigurator.configure(ConfigManager.getProperty("SYSCONFIG.LOG4J_CONFIG_PATH") + "log4j.properties");
		
		logger = Logger.getLogger(Log.class);
	}

	private Log() {
	}

	//configuration parameters
	public static final String LOG_CONFIG = "LOGCONFIG";
	private static final String LOG_PREFIX = LOG_CONFIG + ".";
	//LOG level should be {trace | debug | info | warn | error | fatal | none}
	private static final String LOGLEVEL = "LOG_LEVEL";
	//LOG destination should be {default | filename}

	private static final String SHOWLOGTIIME = "LOG_SHOW_TIME";

	public static final int LOG_LEVEL_TRACE = 1;
	public static final int LOG_LEVEL_DEBUG = 2;
	public static final int LOG_LEVEL_INFO = 3;
	public static final int LOG_LEVEL_WARN = 4;
	public static final int LOG_LEVEL_ERROR = 5;
	public static final int LOG_LEVEL_FATAL = 6;
	public static final int LOG_LEVEL_ALL = (LOG_LEVEL_TRACE - 1);
	public static final int LOG_LEVEL_OFF = (LOG_LEVEL_FATAL + 1);
	private static boolean m_showDateTime = false;
	private static int m_currentLogLevel = LOG_LEVEL_ALL;

	protected static boolean isLevelEnabled(int logLevel) {
		return (logLevel >= m_currentLogLevel);
	}

	public static void setShowDateTime(boolean showDateTime) {
		m_showDateTime = showDateTime;
	}

	public static final void debug(Object message) {
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			if (ourInstance == null) init();
			log(LOG_LEVEL_DEBUG, message, null);
		}
	}

	public static final void debug(Object message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			log(LOG_LEVEL_DEBUG, message, t);
		}
	}
	public static final void debug(long message) {
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			if (ourInstance == null) init();
			log(LOG_LEVEL_DEBUG, message, null);
		}
	}

	public static final void debug(long message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			log(LOG_LEVEL_DEBUG, message, t);
		}
	}
	public static final void debug(int message) {
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			if (ourInstance == null) init();
			log(LOG_LEVEL_DEBUG, message, null);
		}
	}

	public static final void debug(int message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			log(LOG_LEVEL_DEBUG, message, t);
		}
	}
	public static final void debug(float message) {
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			if (ourInstance == null) init();
			log(LOG_LEVEL_DEBUG, message, null);
		}
	}

	public static final void debug(float message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			log(LOG_LEVEL_DEBUG, message, t);
		}
	}
	public static final void debug(double message) {
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			if (ourInstance == null) init();
			log(LOG_LEVEL_DEBUG, message, null);
		}
	}

	public static final void debug(double message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			log(LOG_LEVEL_DEBUG, message, t);
		}
	}
	public static final void debug(char[] message) {
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			if (ourInstance == null) init();
			log(LOG_LEVEL_DEBUG, message, null);
		}
	}

	public static final void debug(char[] message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			log(LOG_LEVEL_DEBUG, message, t);
		}
	}
	public static final void debug(char message) {
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			if (ourInstance == null) init();
			log(LOG_LEVEL_DEBUG, message, null);
		}
	}

	public static final void debug(char message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			log(LOG_LEVEL_DEBUG, message, t);
		}
	}
	public static final void debug(boolean message) {
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			if (ourInstance == null) init();
			log(LOG_LEVEL_DEBUG, message, null);
		}
	}

	public static final void debug(boolean message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			log(LOG_LEVEL_DEBUG, message, t);
		}
	}
	public static final void debug(String message) {
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			if (ourInstance == null) init();
			log(LOG_LEVEL_DEBUG, message, null);
		}
	}

	public static final void debug(String message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_DEBUG)) {
			log(LOG_LEVEL_DEBUG, message, t);
		}
	}

	public static final void trace(Object message) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_TRACE)) {
			log(LOG_LEVEL_TRACE, message, null);
		}
	}
	public static final String getSimpleClassName(Object o) {
		if (o==null) return "null";
		else {
			final String cn = o.getClass().getName();
			final int cntLimit = cn.startsWith("java.") ? 1 : 3;
			int i;
			int dotCnt = 0;
			for (i = cn.length()-1; i >= 0; i--) {
				if (cn.charAt(i)=='.') {
					dotCnt++;
					if (dotCnt==cntLimit) break;
				}
			}
			return cn.substring(i+1);
		}
	}
	public static final void trace(Object o, String m) {
		trace("["+getSimpleClassName(o)+"] "+m);
	}

	public static final String collectionToString(java.util.Collection c) {
		if (c==null) return null;
		StringBuffer ret = new StringBuffer();
		int cnt=0;
		for (java.util.Iterator i=c.iterator(); i.hasNext(); cnt++) {
			Object o = i.next();
			ret.append(Integer.toString(cnt)+" ["+getSimpleClassName(o)+"] "+(o==null?"":o.toString()));
			ret.append("\n");
		}
		return ret.toString();
	}
	public static final void trace(Object o, java.util.Collection c) {
		trace("["+getSimpleClassName(o)+"] "
				+getSimpleClassName(c)
				+(c==null? ": null" : Integer.toString(c.size())+":\n"+collectionToString(c)));
	}
	public static final void trace(Object o, Object[] ary) {
		if (ary==null) trace(o, "null");
		else trace(o, java.util.Arrays.asList(ary));
	}

	public static final void trace(Object message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_TRACE)) {
			log(LOG_LEVEL_TRACE, message, t);
		}
	}
    public static final void trace(long message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, null);
        }
    }

    public static final void trace(long message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, t);
        }
    }
    public static final void trace(int message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, null);
        }
    }

    public static final void trace(int message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, t);
        }
    }
    public static final void trace(float message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, null);
        }
    }

    public static final void trace(float message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, t);
        }
    }
    public static final void trace(double message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, null);
        }
    }

    public static final void trace(double message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, t);
        }
    }
    public static final void trace(char[] message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, null);
        }
    }

    public static final void trace(char[] message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, t);
        }
    }
    public static final void trace(char message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, null);
        }
    }

    public static final void trace(char message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, t);
        }
    }
    public static final void trace(boolean message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, null);
        }
    }

    public static final void trace(boolean message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, t);
        }
    }
    public static final void trace(String message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, null);
        }
    }
    public static final void tracebox(String m) {
    	trace(box(m));
    }
    public static final String box(String m) {
    	if (m==null) return null;
    	int n=0;
    	String[] ls = m.split("\n");
    	for (int i=0; i < ls.length; i++) { if (n < ls[i].length()) n = ls[i].length();}
    	StringBuffer ret = new StringBuffer(n*3+5);
    	ret.append("\n");
    	for (int i=0; i < n; i++) {
    		ret.append("=");
    	}
    	ret.append("\n");
    	ret.append(m);
    	ret.append("\n");
    	for (int i=0; i < n; i++) {
    		ret.append("=");
    	}
    	return ret.toString();
    }

    public static final void trace(String message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_TRACE)) {
            log(LOG_LEVEL_TRACE, message, t);
        }
    }

	public static final void info(Object message) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_INFO)) {
			log(LOG_LEVEL_INFO, message, null);
		}
	}

	public static final void info(Object message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_INFO)) {
			log(LOG_LEVEL_INFO, message, t);
		}
	}
    public static final void info(long message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, null);
        }
    }

    public static final void info(long message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, t);
        }
    }
    public static final void info(int message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, null);
        }
    }

    public static final void info(int message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, t);
        }
    }
    public static final void info(float message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, null);
        }
    }

    public static final void info(float message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, t);
        }
    }
    public static final void info(double message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, null);
        }
    }

    public static final void info(double message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, t);
        }
    }
    public static final void info(char[] message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, null);
        }
    }

    public static final void info(char[] message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, t);
        }
    }
    public static final void info(char message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, null);
        }
    }

    public static final void info(char message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, t);
        }
    }
    public static final void info(boolean message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, null);
        }
    }

    public static final void info(boolean message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, t);
        }
    }
    public static final void info(String message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, null);
        }
    }

    public static final void info(String message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_INFO)) {
            log(LOG_LEVEL_INFO, message, t);
        }
    }

	public static final void warn(Object message) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_WARN)) {
			log(LOG_LEVEL_WARN, message, null);
		}
	}

	public static final void warn(Object message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_WARN)) {
			log(LOG_LEVEL_WARN, message, t);
		}
	}
	public static final void warn(long message) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_WARN)) {
			log(LOG_LEVEL_WARN, message, null);
		}
	}

	public static final void warn(long message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_WARN)) {
			log(LOG_LEVEL_WARN, message, t);
		}
	}
    public static final void warn(int message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, null);
        }
    }

    public static final void warn(int message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, t);
        }
    }
    public static final void warn(float message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, null);
        }
    }

    public static final void warn(float message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, t);
        }
    }
    public static final void warn(double message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, null);
        }
    }

    public static final void warn(double message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, t);
        }
    }
    public static final void warn(char[] message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, null);
        }
    }

    public static final void warn(char[] message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, t);
        }
    }
    public static final void warn(char message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, null);
        }
    }

    public static final void warn(char message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, t);
        }
    }
    public static final void warn(boolean message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, null);
        }
    }

    public static final void warn(boolean message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, t);
        }
    }
    public static final void warn(String message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, null);
        }
    }

    public static final void warn(String message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_WARN)) {
            log(LOG_LEVEL_WARN, message, t);
        }
    }


	public static final void error(Object message) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_ERROR)) {
			log(LOG_LEVEL_ERROR, message, null);
		}
	}

	public static final void error(Object message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_ERROR)) {
			log(LOG_LEVEL_ERROR, message, t);
		}
	}
	public static final void error(long message) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_ERROR)) {
			log(LOG_LEVEL_ERROR, message, null);
		}
	}

	public static final void error(long message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_ERROR)) {
			log(LOG_LEVEL_ERROR, message, t);
		}
	}
    public static final void error(int message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, null);
        }
    }

    public static final void error(int message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, t);
        }
    }
    public static final void error(float message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, null);
        }
    }

    public static final void error(float message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, t);
        }
    }
    public static final void error(double message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, null);
        }
    }

    public static final void error(double message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, t);
        }
    }
    public static final void error(char[] message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, null);
        }
    }

    public static final void error(char[] message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, t);
        }
    }
    public static final void error(char message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, null);
        }
    }

    public static final void error(char message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, t);
        }
    }
    public static final void error(boolean message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, null);
        }
    }

    public static final void error(boolean message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, t);
        }
    }
    public static final void error(String message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, null);
        }
    }

    public static final void error(String message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, t);
        }
    }

	public static final void fatal(Object message) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_FATAL)) {
			log(LOG_LEVEL_FATAL, message, null);
		}
	}

	public static final void fatal(Object message, Throwable t) {
		if (ourInstance == null) init();
		if (isLevelEnabled(LOG_LEVEL_FATAL)) {
			log(LOG_LEVEL_FATAL, message, t);
		}
	}
    public static final void fatal(long message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, null);
        }
    }

    public static final void fatal(long message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, t);
        }
    }
    public static final void fatal(int message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, null);
        }
    }

    public static final void fatal(int message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, t);
        }
    }
    public static final void fatal(float message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, null);
        }
    }

    public static final void fatal(float message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, t);
        }
    }
    public static final void fatal(double message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, null);
        }
    }

    public static final void fatal(double message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, t);
        }
    }
    public static final void fatal(char[] message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, null);
        }
    }

    public static final void fatal(char[] message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, t);
        }
    }
    public static final void fatal(char message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, null);
        }
    }

    public static final void fatal(char message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, t);
        }
    }
    public static final void fatal(boolean message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, null);
        }
    }

    public static final void fatal(boolean message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, t);
        }
    }
    public static final void fatal(String message) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, null);
        }
    }

    public static final void fatal(String message, Throwable t) {
        if (ourInstance == null) init();
        if (isLevelEnabled(LOG_LEVEL_FATAL)) {
            log(LOG_LEVEL_FATAL, message, t);
        }
    }

	private static synchronized void init() {
		ourInstance = null;

		//log level
		String level = ConfigManager.getProperty(LOG_PREFIX + LOGLEVEL);
		if (level != null) level = level.toLowerCase();
		if (level == null)
			m_currentLogLevel = LOG_LEVEL_ALL;
		else if (level.equals("trace"))
			m_currentLogLevel = LOG_LEVEL_TRACE;
		else if (level.equals("debug"))
			m_currentLogLevel = LOG_LEVEL_DEBUG;
		else if (level.equals("info"))
			m_currentLogLevel = LOG_LEVEL_INFO;
		else if (level.equals("warn"))
			m_currentLogLevel = LOG_LEVEL_WARN;
		else if (level.equals("error"))
			m_currentLogLevel = LOG_LEVEL_ERROR;
		else if (level.equals("fatal"))
			m_currentLogLevel = LOG_LEVEL_FATAL;
		else if (level.equals("none"))
			m_currentLogLevel = LOG_LEVEL_OFF;
		else
			m_currentLogLevel = LOG_LEVEL_ALL;

		//show log time?
		String showtime = ConfigManager.getProperty(LOG_PREFIX + SHOWLOGTIIME);
		if (showtime != null) showtime = showtime.toLowerCase();
		if (showtime == null || !showtime.equals("true"))
			m_showDateTime = false;
		else
			m_showDateTime = true;

		ourInstance = new Log();
	}

	private static void log(int type, Object message, Throwable t) {
		// use a string buffer for better performance
		StringBuffer buf = new StringBuffer();
		// append date-time if so configured
		if (m_showDateTime) {
			buf.append(new Timestamp(System.currentTimeMillis()));
			buf.append(" ");
		}
		// append a readable representation of the log leve
		switch (type) {
			case LOG_LEVEL_TRACE:
				buf.append("[TRACE] ");
				break;
			case LOG_LEVEL_DEBUG:
				buf.append("[DEBUG] ");
				break;
			case LOG_LEVEL_INFO:
				buf.append("[INFO] ");
				break;
			case LOG_LEVEL_WARN:
				buf.append("[WARN] ");
				break;
			case LOG_LEVEL_ERROR:
				buf.append("[ERROR] ");
				break;
			case LOG_LEVEL_FATAL:
				buf.append("[FATAL] ");
				break;
		}

		// append the message
		buf.append(String.valueOf(message));
		// append stack trace if not null
		if (t != null) {
			buf.append(" <");
			buf.append(t.toString());
			buf.append(">");

			java.io.StringWriter sw = new java.io.StringWriter(1024);
			java.io.PrintWriter pw = new java.io.PrintWriter(sw);
			t.printStackTrace(pw);
			pw.close();
			buf.append(sw.toString());
		}
		
		toLogger(type, buf);
	}

	private static void log(int type, int message, Throwable t) {
		// use a string buffer for better performance
		StringBuffer buf = new StringBuffer();
		// append date-time if so configured
		if (m_showDateTime) {
			buf.append(new Timestamp(System.currentTimeMillis()));
			buf.append(" ");
		}
		// append a readable representation of the log leve
		switch (type) {
			case LOG_LEVEL_TRACE:
				buf.append("[TRACE] ");
				break;
			case LOG_LEVEL_DEBUG:
				buf.append("[DEBUG] ");
				break;
			case LOG_LEVEL_INFO:
				buf.append("[INFO] ");
				break;
			case LOG_LEVEL_WARN:
				buf.append("[WARN] ");
				break;
			case LOG_LEVEL_ERROR:
				buf.append("[ERROR] ");
				break;
			case LOG_LEVEL_FATAL:
				buf.append("[FATAL] ");
				break;
		}

		// append the message
		buf.append(String.valueOf(message));
		// append stack trace if not null
		if (t != null) {
			buf.append(" <");
			buf.append(t.toString());
			buf.append(">");

			java.io.StringWriter sw = new java.io.StringWriter(1024);
			java.io.PrintWriter pw = new java.io.PrintWriter(sw);
			t.printStackTrace(pw);
			pw.close();
			buf.append(sw.toString());
		}

		toLogger(type, buf);
	}
	private static void log(int type, long message, Throwable t) {
		// use a string buffer for better performance
		StringBuffer buf = new StringBuffer();
		// append date-time if so configured
		if (m_showDateTime) {
			buf.append(new Timestamp(System.currentTimeMillis()));
			buf.append(" ");
		}
		// append a readable representation of the log leve
		switch (type) {
			case LOG_LEVEL_TRACE:
				buf.append("[TRACE] ");
				break;
			case LOG_LEVEL_DEBUG:
				buf.append("[DEBUG] ");
				break;
			case LOG_LEVEL_INFO:
				buf.append("[INFO] ");
				break;
			case LOG_LEVEL_WARN:
				buf.append("[WARN] ");
				break;
			case LOG_LEVEL_ERROR:
				buf.append("[ERROR] ");
				break;
			case LOG_LEVEL_FATAL:
				buf.append("[FATAL] ");
				break;
		}

		// append the message
		buf.append(String.valueOf(message));
		// append stack trace if not null
		if (t != null) {
			buf.append(" <");
			buf.append(t.toString());
			buf.append(">");

			java.io.StringWriter sw = new java.io.StringWriter(1024);
			java.io.PrintWriter pw = new java.io.PrintWriter(sw);
			t.printStackTrace(pw);
			pw.close();
			buf.append(sw.toString());
		}

		toLogger(type, buf);
	}
	private static void log(int type, float message, Throwable t) {
		// use a string buffer for better performance
		StringBuffer buf = new StringBuffer();
		// append date-time if so configured
		if (m_showDateTime) {
			buf.append(new Timestamp(System.currentTimeMillis()));
			buf.append(" ");
		}
		// append a readable representation of the log leve
		switch (type) {
			case LOG_LEVEL_TRACE:
				buf.append("[TRACE] ");
				break;
			case LOG_LEVEL_DEBUG:
				buf.append("[DEBUG] ");
				break;
			case LOG_LEVEL_INFO:
				buf.append("[INFO] ");
				break;
			case LOG_LEVEL_WARN:
				buf.append("[WARN] ");
				break;
			case LOG_LEVEL_ERROR:
				buf.append("[ERROR] ");
				break;
			case LOG_LEVEL_FATAL:
				buf.append("[FATAL] ");
				break;
		}

		// append the message
		buf.append(String.valueOf(message));
		// append stack trace if not null
		if (t != null) {
			buf.append(" <");
			buf.append(t.toString());
			buf.append(">");

			java.io.StringWriter sw = new java.io.StringWriter(1024);
			java.io.PrintWriter pw = new java.io.PrintWriter(sw);
			t.printStackTrace(pw);
			pw.close();
			buf.append(sw.toString());
		}

		toLogger(type, buf);
	}
	private static void log(int type, double message, Throwable t) {
		// use a string buffer for better performance
		StringBuffer buf = new StringBuffer();
		// append date-time if so configured
		if (m_showDateTime) {
			buf.append(new Timestamp(System.currentTimeMillis()));
			buf.append(" ");
		}
		// append a readable representation of the log leve
		switch (type) {
			case LOG_LEVEL_TRACE:
				buf.append("[TRACE] ");
				break;
			case LOG_LEVEL_DEBUG:
				buf.append("[DEBUG] ");
				break;
			case LOG_LEVEL_INFO:
				buf.append("[INFO] ");
				break;
			case LOG_LEVEL_WARN:
				buf.append("[WARN] ");
				break;
			case LOG_LEVEL_ERROR:
				buf.append("[ERROR] ");
				break;
			case LOG_LEVEL_FATAL:
				buf.append("[FATAL] ");
				break;
		}

		// append the message
		buf.append(String.valueOf(message));
		// append stack trace if not null
		if (t != null) {
			buf.append(" <");
			buf.append(t.toString());
			buf.append(">");

			java.io.StringWriter sw = new java.io.StringWriter(1024);
			java.io.PrintWriter pw = new java.io.PrintWriter(sw);
			t.printStackTrace(pw);
			pw.close();
			buf.append(sw.toString());
		}

		toLogger(type, buf);
	}
	private static void log(int type, char[] message, Throwable t) {
		// use a string buffer for better performance
		StringBuffer buf = new StringBuffer();
		// append date-time if so configured
		if (m_showDateTime) {
			buf.append(new Timestamp(System.currentTimeMillis()));
			buf.append(" ");
		}
		// append a readable representation of the log leve
		switch (type) {
			case LOG_LEVEL_TRACE:
				buf.append("[TRACE] ");
				break;
			case LOG_LEVEL_DEBUG:
				buf.append("[DEBUG] ");
				break;
			case LOG_LEVEL_INFO:
				buf.append("[INFO] ");
				break;
			case LOG_LEVEL_WARN:
				buf.append("[WARN] ");
				break;
			case LOG_LEVEL_ERROR:
				buf.append("[ERROR] ");
				break;
			case LOG_LEVEL_FATAL:
				buf.append("[FATAL] ");
				break;
		}

		// append the message
		buf.append(String.valueOf(message));
		// append stack trace if not null
		if (t != null) {
			buf.append(" <");
			buf.append(t.toString());
			buf.append(">");

			java.io.StringWriter sw = new java.io.StringWriter(1024);
			java.io.PrintWriter pw = new java.io.PrintWriter(sw);
			t.printStackTrace(pw);
			pw.close();
			buf.append(sw.toString());
		}

		toLogger(type, buf);
	}
	private static void log(int type, char message, Throwable t) {
		// use a string buffer for better performance
		StringBuffer buf = new StringBuffer();
		// append date-time if so configured
		if (m_showDateTime) {
			buf.append(new Timestamp(System.currentTimeMillis()));
			buf.append(" ");
		}
		// append a readable representation of the log leve
		switch (type) {
			case LOG_LEVEL_TRACE:
				buf.append("[TRACE] ");
				break;
			case LOG_LEVEL_DEBUG:
				buf.append("[DEBUG] ");
				break;
			case LOG_LEVEL_INFO:
				buf.append("[INFO] ");
				break;
			case LOG_LEVEL_WARN:
				buf.append("[WARN] ");
				break;
			case LOG_LEVEL_ERROR:
				buf.append("[ERROR] ");
				break;
			case LOG_LEVEL_FATAL:
				buf.append("[FATAL] ");
				break;
		}

		// append the message
		buf.append(String.valueOf(message));
		// append stack trace if not null
		if (t != null) {
			buf.append(" <");
			buf.append(t.toString());
			buf.append(">");

			java.io.StringWriter sw = new java.io.StringWriter(1024);
			java.io.PrintWriter pw = new java.io.PrintWriter(sw);
			t.printStackTrace(pw);
			pw.close();
			buf.append(sw.toString());
		}

		toLogger(type, buf);
	}
	private static void log(int type, boolean message, Throwable t) {
		// use a string buffer for better performance
		StringBuffer buf = new StringBuffer();
		// append date-time if so configured
		if (m_showDateTime) {
			buf.append(new Timestamp(System.currentTimeMillis()));
			buf.append(" ");
		}
		// append a readable representation of the log leve
		switch (type) {
			case LOG_LEVEL_TRACE:
				buf.append("[TRACE] ");
				break;
			case LOG_LEVEL_DEBUG:
				buf.append("[DEBUG] ");
				break;
			case LOG_LEVEL_INFO:
				buf.append("[INFO] ");
				break;
			case LOG_LEVEL_WARN:
				buf.append("[WARN] ");
				break;
			case LOG_LEVEL_ERROR:
				buf.append("[ERROR] ");
				break;
			case LOG_LEVEL_FATAL:
				buf.append("[FATAL] ");
				break;
		}

		// append the message
		buf.append(String.valueOf(message));
		// append stack trace if not null
		if (t != null) {
			buf.append(" <");
			buf.append(t.toString());
			buf.append(">");

			java.io.StringWriter sw = new java.io.StringWriter(1024);
			java.io.PrintWriter pw = new java.io.PrintWriter(sw);
			t.printStackTrace(pw);
			pw.close();
			buf.append(sw.toString());
		}

		toLogger(type, buf);
	}
	protected static void log(int type, String message, Throwable t) {
		// use a string buffer for better performance
		StringBuffer buf = new StringBuffer();
		// append date-time if so configured
		if (m_showDateTime) {
			buf.append(new Timestamp(System.currentTimeMillis()));
			buf.append(" ");
		}
		// append a readable representation of the log leve
		switch (type) {
			case LOG_LEVEL_TRACE:
				buf.append("[TRACE] ");
				break;
			case LOG_LEVEL_DEBUG:
				buf.append("[DEBUG] ");
				break;
			case LOG_LEVEL_INFO:
				buf.append("[INFO] ");
				break;
			case LOG_LEVEL_WARN:
				buf.append("[WARN] ");
				break;
			case LOG_LEVEL_ERROR:
				buf.append("[ERROR] ");
				break;
			case LOG_LEVEL_FATAL:
				buf.append("[FATAL] ");
				break;
		}

		// append the message
		buf.append(String.valueOf(message));
		// append stack trace if not null
		if (t != null) {
			buf.append(" <");
			buf.append(t.toString());
			buf.append(">");

			java.io.StringWriter sw = new java.io.StringWriter(1024);
			java.io.PrintWriter pw = new java.io.PrintWriter(sw);
			t.printStackTrace(pw);
			pw.close();
			buf.append(sw.toString());
		}
		
		toLogger(type, buf);
	}
	
	private static void toLogger(int type, StringBuffer buf) {

		// print to PrintStream
		switch (type) {
			case LOG_LEVEL_TRACE:
				logger.trace(buf.toString());
				break;
			case LOG_LEVEL_DEBUG:
				logger.debug(buf.toString());
				break;
			case LOG_LEVEL_INFO:
				logger.info(buf.toString());
				break;
			case LOG_LEVEL_WARN:
				logger.warn(buf.toString());
				break;
			case LOG_LEVEL_ERROR:
				logger.error(buf.toString());
				break;
			case LOG_LEVEL_FATAL:
				logger.fatal(buf.toString());
				break;
		}
	}
	
	public static void main(String args[]) {
		Log.trace("trace");
		Log.debug("debug");
		Log.error("error");
		Log.info("info");
		Log.fatal("fatal");
		Log.warn("warn", new Exception("what?"));
	}
}